<template>
  <div>
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.name" />
    </el-checkbox-group>
    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getUserStaffPhoto } from '@/api/user'
import { getRoles } from '@/api/roles'
export default {
  name: 'AssignRole',
  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      checkList: [],
      list: []
    }
  },
  created() {
    this.loadRoles()
    this.loadRolesRows()
  },
  methods: {
    async loadRoles() {
      try {
        const res = await getUserStaffPhoto(this.id)
        // console.log(res)
        this.checkList = res.data.roleIds
      } catch (e) {
        console.log(e)
      }
    },
    async  loadRolesRows() {
      const res = await getRoles()
      // console.log(res)
      this.list = res.data.rows
    }
  }
}
</script>

<style scoped>
</style>
